package com.example.mapper;

import com.example.entity.Helper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 操作helper相关数据接口
*/
public interface HelperMapper {
    void insert(Helper helper);

    @Select("select helper.*, volunteer.name as volunteerName, user.name as userName from helper " +
            "left join volunteer on helper.volunteer_id = volunteer.id " +
            "left join user on helper.user_id = user.id")
    List<Helper> selectAll();

    @Select("select helper.*, volunteer.name as volunteerName, user.name as userName from helper " +
            "left join volunteer on helper.volunteer_id = volunteer.id " +
            "left join user on helper.user_id = user.id " +
            "where helper.name like concat('%', #{name}, '%')")
    List<Helper> selectByName(@Param("name") String name);


    void updateById(Helper helper);

    @Delete("delete from helper where id = #{id}")
    void deleteById(Integer id);

    @Select("select*from helper where help_id=#{helpId} and user_id=#{userId}")
    List<Helper> selectByHelpIdAndUserId(@Param("helpId") Integer helpId, @Param("userId")Integer userId);

    @Select("select helper.*, volunteer.name as volunteerName, user.name as userName from helper " +
            "left join volunteer on helper.volunteer_id = volunteer.id " +
            "left join user on helper.user_id = user.id " +
            "where helper.name like concat('%', #{name}, '%') and user_id=#{userId}")
    List<Helper> selectByNameAndUserId(@Param("name")String name, @Param("userId")Integer userId);

    @Select("select helper.*, volunteer.name as volunteerName, user.name as userName from helper " +
            "left join volunteer on helper.volunteer_id = volunteer.id " +
            "left join user on helper.user_id = user.id " +
            "where user_id=#{userId}")
    List<Helper> selectAllByUserId(Integer userId);

    @Select("select helper.*, volunteer.name as volunteerName, user.name as userName from helper " +
            "left join volunteer on helper.volunteer_id = volunteer.id " +
            "left join user on helper.user_id = user.id " +
            "where helper.name like concat('%', #{name}, '%') and volunteer_id=#{volunteerId}")
    List<Helper> selectByNameAndVolunteerId(@Param("name")String name, @Param("volunteerId")Integer volunteerId);

    @Select("select helper.*, volunteer.name as volunteerName, user.name as userName from helper " +
            "left join volunteer on helper.volunteer_id = volunteer.id " +
            "left join user on helper.user_id = user.id " +
            "where volunteer_id=#{volunteerId}")
    List<Helper> selectAllByVolunteerId(Integer volunteerId);

    @Select("select * from helper where id = #{id}")
    Helper selecctById(Integer id);
}